package Router

import (
	cache "github.com/chenyahui/gin-cache"
	"github.com/chenyahui/gin-cache/persist"
	"github.com/gin-gonic/gin"
	"time"
	"web_back_go/Controller"
)

func InitRouter(r *gin.Engine) {
	// 创建一个内存用来缓存
	memoryStore := persist.NewMemoryStore(1 * time.Minute)

	userGroup := r.Group("/user")
	{
		userGroup.GET("/info", Controller.GetUserInfo)
		userGroup.POST("/info", Controller.UpdateUserInfo)
	}

	// 首页图片
	r.GET("/indexImgs", Controller.GetIndexImagesController)

	// 用户注册登录
	r.POST("/user/register", Controller.Register)
	r.POST("/login", Controller.Login)
	r.POST("/logOut", Controller.UserLogout)
	//refresh
	r.POST("/token/refresh", Controller.ReflushToken)

	// 公告相关
	noticeGroup := r.Group("/shop/notice")
	{
		noticeGroup.GET("/topNoticeList", Controller.GetTopNoticeList)
		noticeGroup.GET("/noticeList", Controller.GetShopNoticePage)
		noticeGroup.GET("/info/:id", Controller.GetNoticeById)
	}

	// 购物车
	cartGroup := r.Group("/p/shopCart")
	{
		cartGroup.GET("/prodCount", Controller.GetCartProdCount)
		cartGroup.POST("/info", Controller.GetShopCartItemByUserId)
		cartGroup.POST("/changeItem", Controller.AddCartItem)
		cartGroup.POST("/totalPay", Controller.GetTotalPay)
		cartGroup.DELETE("/deleteItem", Controller.DelShopCartItem)
		cartGroup.DELETE("/deleteAll", Controller.DeleteAllShopCartItems)
		//cartGroup.GET("/expiryProdList", Controller.GetExpiryProdList)           // 假设这是获取失效商品列表的控制器
		//cartGroup.DELETE("/cleanExpiryProdList", Controller.CleanExpiryProdList) // 假设这是删除用户失效商品的控制器
	}

	//订单相关
	myOrderGroup := r.Group("/p/myOrder")
	{
		myOrderGroup.GET("/orderCount", Controller.GetOrderCount)                //获取我的订单订单数量
		myOrderGroup.GET("/myOrder", Controller.GetMyOrderList)                  //订单列表信息
		myOrderGroup.GET("/orderDetail", Controller.OrderDetail)                 //订单详情
		myOrderGroup.PUT("/receipt/:orderNumber", Controller.OrderReceipt)       //确认收货
		myOrderGroup.PUT("/cancel/:orderNumber", Controller.CancelOrder)         //取消订单
		myOrderGroup.DELETE("/:orderNumber", Controller.DeleOrdersByOrderNumber) //删除订单
	}

	//提交订单
	orderGroup := r.Group("/p/order")
	{
		orderGroup.POST("/confirm", Controller.ConfirmOrder) //结算，生成订单信息
		orderGroup.POST("/submit", Controller.SubmitOrders)  //根据传入的参数判断是否为购物车提交订单，同时对购物车进行删除，用户开始进行支付
		orderGroup.POST("/normalPay", Controller.NormalPay)  //根据订单号进行支付
		orderGroup.POST("/pay", Controller.Pay)              //根据订单号进行支付
		orderGroup.POST("/ZFBPay", Controller.ZFBPay)
	}

	// 商品接口
	prodGroup := r.Group("/prod")
	{
		prodGroup.GET("/tag/prodTagList", Controller.GetProdTagList)     //商品分组标签列表
		prodGroup.GET("/prodListByTagId", Controller.GetProdListByTagId) //通过分组标签获取商品列表
		prodGroup.GET("/prodInfo", Controller.GetProdInfoById)           //商品详情信息
		prodGroup.GET("/tagProdList", Controller.GetTagProdList)         //首页所有标签商品接口
		prodGroup.GET("/pageProd", Controller.GetProdList)               //通过分类id商品列表信息
		prodGroup.GET("/moreBuyProdList", Controller.MoreBuyProdList)    //每日疯抢
		prodGroup.GET("/lastedProdPage", Controller.GetLastedProdPage)   //新品推荐
	}

	// 商品评论
	prodCommGroup := r.Group("/prodComm")
	{
		prodCommGroup.GET("/prodCommData", Controller.GetProdCommDataById)           //返回商品评论数据(好评率 好评数量 中评数 差评数)
		prodCommGroup.GET("/prodCommPageByProd", Controller.GetProdCommPageByProdId) //根据商品返回评论分页数据
		prodCommGroup.GET("/prodCommPageByUser", Controller.GetUserCommonPage)       //根据用户返回评论分页数据
		prodCommGroup.DELETE("", Controller.DeleteProdComm)                          //删除商品评论
		prodCommGroup.POST("", Controller.AddProdCommPage)                           //新增商品评论
	}

	// 商品收藏
	collectionGroup := r.Group("/p/user/collection")
	{
		collectionGroup.GET("/isCollection", Controller.IsCollection)
		collectionGroup.GET("/count", Controller.GetUserCollectionCount)
		collectionGroup.GET("/prods", Controller.GetCollectionProdsPage)
		collectionGroup.POST("/addOrCancel", Controller.AddOrCancelCollection)
		collectionGroup.GET("/page", Controller.GetUserCollectionDtoPageByUserId)
	}

	// 商品热搜
	searchGroup := r.Group("/search")
	{
		searchGroup.GET("/hotSearchByShopId", Controller.GetHotSearchByShopId)
		searchGroup.GET("/hotSearch", Controller.GetHotSearchAll)
		searchGroup.GET("/searchProdPage", Controller.GetSearchProdPage)
	}

	// 商品分类
	r.GET("/category/categoryInfo", Controller.GetCategoryInfo)

	// 地址接口
	addressGroup := r.Group("/p/address")
	{
		addressGroup.GET("/list", Controller.GetUserDvyList)                 //用户地址列表
		addressGroup.GET("/addrInfo/:addrId", Controller.AddressInfo)        //获取地址信息
		addressGroup.POST("/addAddr", Controller.AddAddress)                 //新增用户地址
		addressGroup.PUT("/defaultAddr/:addrId", Controller.DefaultAddress)  //设置默认地址
		addressGroup.PUT("/updateAddr", Controller.UpdateAddress)            //修改订单用户地址
		addressGroup.DELETE("/deleteAddr/:addrId", Controller.DeleteAddress) //删除订单用户地址
	}

	//获取省市区信息
	r.GET("p/area/listByPid", cache.CacheByRequestURI(memoryStore, 2*time.Minute), Controller.GetAreaListByPid)

	//sku规格接口
	r.GET("/sku/getSkuList", Controller.GetSkuListByProdId)

	//查看物流
	r.GET("/delivery/check", Controller.CheckDelivery)

	r.GET("/test", Controller.TestController)

	//店家回复
	userMessageGroup := r.Group("/p/user/message")
	{
		userMessageGroup.GET("/page", Controller.GetUserMessage)
		userMessageGroup.GET("/count", Controller.GetUserMessageCount)
	}

}
